import java.util.ArrayList;
import java.util.List;

public class ComponentComposite extends Component{

    private List<Component> childrenList = new ArrayList<Component>();

    public ComponentComposite(String componentName) {
        super(componentName);
    }

    @Override
    public boolean addChild(Component child) {
        return this.childrenList.add(child);
    }

    @Override
    public boolean removeChild(Component child) {
        return this.childrenList.remove(child);
    }

    @Override
    public Component getChild(Integer childIndex) {
        return this.childrenList.get(childIndex);
    }

    @Override
    public void operation() {
        System.out.println("-----------------------------------------------------------------");
        System.out.println("容器节点：" + getComponentName());
            for (Component currentComponent : childrenList) {
                currentComponent.operation();
            }
            System.out.println("-----------------------------------------------------------------");
        }

}
